#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>

using namespace std;
using LL = long long;
/*
对一颗无向图来说满足下面两个结论
对于第一颗生成树, 对于没有选上的m-n+1条边, 全都是祖孙边             -------------求dfs树
对于第二颗生成树, 对于没有选上的m-n+1条边, 全部都是非祖孙边         --------------求bfs树

*/

const int N = 3e5 + 10;
vector<int> G[N];
int n, m;
bool st[N];

void dfs(int u)
{
    st[u] = 1;
    for(auto v : G[u])
    {
        if(st[v]) continue;
        cout << u << " " << v << endl;
        dfs(v);
    }
}

int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    cin >> n >> m;
    for(int i = 0; i < m; i ++ )
    {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    
    dfs(1);
    memset(st, 0, sizeof st);
    queue<int> q;
    q.push(1), st[1] = 1;
    while(q.size())
    {
        int t = q.front(); q.pop();
        for(auto v : G[t])
        {
            if(st[v]) continue;
            st[v] = 1;
            q.push(v);
            cout << t << " " << v << endl;
        }
    }
}